import api from '@/api/api'
import router from '@/router'
import { useUserStore } from '@/stores/user'
// 封装接口
// 登录
export async function login(formData) {
	const res = await api.post('/login', formData)
	console.log('登录', res)
	if (!res) return
	if (res.data.code === 10000) {
		router.push({ name: 'layout' })
	}
}
// 注册 
export async function register(formData) {
	const res = await api.post('/register', formData)
	console.log('注册', res)
	if (!res) return
	if (res.data.code === 10000) {
		router.push('/login')
	}
}

// 刷新
export async function refreshToken() {
	const store = useUserStore()
	if (!store.accessToken && store.refreshToken) {
		await api.get('/refreshToken', {
			params: {
				refreshToken: store.refreshToken
			}
		})
	}
}